package com.example.watchs.methods;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardWatchEventKinds;
import java.nio.file.WatchEvent;

/**
 * @author w
 * @Description:
 * @DateTime: 2025 07 02 14:42
 **/
public abstract class BaseMethod {
    public abstract void OnCreateFile(Path filePath);

    public abstract void OnDelete(Path filePath);

    public abstract void OnUpdateFile(Path filePath);

    public abstract void OnCreateDir(Path filePath);

    public abstract void OnUpdateDir(Path filePath);

    public boolean toConvert(Path filePath, WatchEvent.Kind<?> kind) {
        boolean isDir = Files.isDirectory(filePath);
        if (kind.equals(StandardWatchEventKinds.ENTRY_CREATE)) {
            if (isDir){
                OnCreateDir(filePath);
            }else{
                OnCreateFile(filePath);
            }
        } else if (kind.equals(StandardWatchEventKinds.ENTRY_DELETE)) {
            OnDelete(filePath);
        } else if (kind.equals(StandardWatchEventKinds.ENTRY_MODIFY)) {
            if (isDir){
                OnUpdateDir(filePath);
            }else{
                OnUpdateFile(filePath);
            }
        } else if (kind.equals(StandardWatchEventKinds.OVERFLOW)) {
            System.out.println(filePath + "事件丢失");
            return true;
        } else {
            return false;
        }
        return true;
    }
}